package com.sptpc.exam;


import com.sptpc.exam.model.Question;
import com.sptpc.exam.model.User;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

// 保存所有的试题

@WebServlet("/usermanage.do")
public class UserManageServlet extends  HttpServlet {
    // 保存所有的试题
    private final List<User> users = new ArrayList<>();

    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        // 加载试题
        User user1 =new User(1,"test01","张三","软件技术");
        User user2 =new User(1,"test02","张三","软件技术");
        User user3 =new User(1,"test03","张三","软件技术");
        users.add(user1);
        users.add(user2);
        users.add(user3);
    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
        {
            request.getSession().setAttribute("users",users);
            request.getRequestDispatcher("userlist.jsp").forward(request, response);

        }
    }
